<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Call Traits</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Utility">
<link rel="up" href="../utilities.html" title="Utilities">
<link rel="prev" href="../../BOOST_BINARY_LITERAL_D.html" title="Macro BOOST_BINARY_LITERAL_D">
<link rel="next" href="../../boost/call_traits.html" title="Struct template call_traits">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../../BOOST_BINARY_LITERAL_D.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../utilities.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../../boost/call_traits.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility.utilities.call_traits"></a><a class="link" href="call_traits.html" title="Call Traits">Call Traits</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="call_traits.html#utility.utilities.call_traits.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="call_traits.html#utility.utilities.call_traits.copy_constructibility">Copy
        constructibility</a></span></dt>
<dt><span class="section"><a href="call_traits.html#utility.utilities.call_traits.examples">Examples</a></span></dt>
<dt><span class="section"><a href="call_traits.html#utility.utilities.call_traits.rationale">Rationale</a></span></dt>
<dt><span class="section"><a href="call_traits.html#call_traits.reference">Reference</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility.utilities.call_traits.introduction"></a><a class="link" href="call_traits.html#utility.utilities.call_traits.introduction" title="Introduction">Introduction</a>
</h4></div></div></div>
<p>
          All of the contents of <a href="../../../../../../boost/call_traits.hpp" target="_top"><code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">call_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code></a> are defined inside <code class="computeroutput"><span class="keyword">namespace</span> <span class="identifier">boost</span></code>.
        </p>
<p>
          The template class <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code></a> encapsulates the "best"
          method to pass a parameter of some type <code class="computeroutput"><span class="identifier">T</span></code>
          to or from a function, and consists of a collection of <code class="computeroutput"><span class="keyword">typedef</span></code>s
          defined as in the table below. The purpose of <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a> is to ensure that
          problems like <a class="link" href="call_traits.html#sec:refs">"references to references"</a>
          never occur, and that parameters are passed in the most efficient manner
          possible, as in the <a class="link" href="call_traits.html#sec:examples">examples</a>. In each
          case, if your existing practice is to use the type defined on the left,
          then replace it with the <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a> defined type on the
          right.
        </p>
<p>
          Note that for compilers that do not support either partial specialization
          or member templates, no benefit will occur from using <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>: the <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a> defined types will
          always be the same as the existing practice in this case. In addition if
          only member templates and not partial template specialisation is support
          by the compiler (for example Visual C++ 6) then <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a> cannot be used with
          array types, although it can still be used to solve the reference to reference
          problem.
        </p>
<div class="table">
<a name="utility.utilities.call_traits.introduction.call_traits_types"></a><p class="title"><b>Table 1.2. <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>
          types</b></p>
<div class="table-contents"><table class="table" summary="call_traits
          types">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                  <p>
                    Existing practice
                  </p>
                </th>
<th>
                  <p>
                    <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>
                    equivalent
                  </p>
                </th>
<th>
                  <p>
                    Description
                  </p>
                </th>
<th>
                  <p>
                    Notes
                  </p>
                </th>
</tr></thead>
<tbody>
<tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">T</span></code>
                  </p>
                  <p>
                    (return by value)
                  </p>
                </td>
<td>
                  <p>
                    <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code></a><code class="computeroutput"><span class="special">::</span><span class="identifier">value_type</span></code>
                  </p>
                </td>
<td>
                  <p>
                    Defines a type that represents the "value" of type
                    <code class="computeroutput"><span class="identifier">T</span></code>.
                  </p>
                  <p>
                    Use this for functions that return by value, or possibly for
                    stored values of type <code class="computeroutput"><span class="identifier">T</span></code>.
                  </p>
                </td>
<td>
                  <p>
                    2
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">T</span><span class="special">&amp;</span></code>
                  </p>
                  <p>
                    (return value)
                  </p>
                </td>
<td>
                  <p>
                    <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code></a><code class="computeroutput"><span class="special">::</span><span class="identifier">reference</span></code>
                  </p>
                </td>
<td>
                  <p>
                    Defines a type that represents a reference to type <code class="computeroutput"><span class="identifier">T</span></code>.
                  </p>
                  <p>
                    Use for functions that would normally return a <code class="computeroutput"><span class="identifier">T</span><span class="special">&amp;</span></code>.
                  </p>
                </td>
<td>
                  <p>
                    1
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span></code>
                  </p>
                  <p>
                    (return value)
                  </p>
                </td>
<td>
                  <p>
                    <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code></a><code class="computeroutput"><span class="special">::</span><span class="identifier">const_reference</span></code>
                  </p>
                </td>
<td>
                  <p>
                    Defines a type that represents a constant reference to type
                    <code class="computeroutput"><span class="identifier">T</span></code>.
                  </p>
                  <p>
                    Use for functions that would normally return a <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span></code>.
                  </p>
                </td>
<td>
                  <p>
                    1
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span></code>
                  </p>
                  <p>
                    (function parameter)
                  </p>
                </td>
<td>
                  <p>
                    <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code></a><code class="computeroutput"><span class="special">::</span><span class="identifier">param_type</span></code>
                  </p>
                </td>
<td>
                  <p>
                    Defines a type that represents the "best" way to pass
                    a parameter of type <code class="computeroutput"><span class="identifier">T</span></code>
                    to a function.
                  </p>
                </td>
<td>
                  <p>
                    1,3
                  </p>
                </td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>
          Notes:
        </p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
              If <code class="computeroutput"><span class="identifier">T</span></code> is already reference
              type, then <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>
              is defined such that <a class="link" href="call_traits.html#sec:refs">"references to references"</a>
              do not occur (requires partial specialization).
            </li>
<li class="listitem">
              If <code class="computeroutput"><span class="identifier">T</span></code> is an array type,
              then <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>
              defines <code class="computeroutput"><span class="identifier">value_type</span></code>
              as a "constant pointer to type" rather than an "array
              of type" (requires partial specialization). Note that if you are
              using <code class="computeroutput"><span class="identifier">value_type</span></code> as
              a stored value then this will result in storing a "constant pointer
              to an array" rather than the array itself. This may or may not
              be a good thing depending upon what you actually need (in other words
              take care!).
            </li>
<li class="listitem">
              If <code class="computeroutput"><span class="identifier">T</span></code> is a small built
              in type or a pointer, then <code class="computeroutput"><span class="identifier">param_type</span></code>
              is defined as <code class="computeroutput"><span class="identifier">T</span> <span class="keyword">const</span></code>,
              instead of <code class="computeroutput"><span class="identifier">T</span> <span class="keyword">const</span><span class="special">&amp;</span></code>. This can improve the ability
              of the compiler to optimize loops in the body of the function if they
              depend upon the passed parameter, the semantics of the passed parameter
              is otherwise unchanged (requires partial specialization).
            </li>
</ol></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility.utilities.call_traits.copy_constructibility"></a><a class="link" href="call_traits.html#utility.utilities.call_traits.copy_constructibility" title="Copy constructibility">Copy
        constructibility</a>
</h4></div></div></div>
<p>
          The following table defines which <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a> types can always be
          copy-constructed from which other types:
        </p>
<div class="table">
<a name="utility.utilities.call_traits.copy_constructibility.which_call_traits_types_can_alwa"></a><p class="title"><b>Table 1.3. Which <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>
          types can always be copy-constructed from which other types</b></p>
<div class="table-contents"><table class="table" summary="Which call_traits
          types can always be copy-constructed from which other types">
<colgroup>
<col>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                </th>
<th>
                  <p>
                    To <code class="computeroutput"><span class="identifier">T</span></code>
                  </p>
                </th>
<th>
                  <p>
                    To <code class="computeroutput"><span class="identifier">value_type</span></code>
                  </p>
                </th>
<th>
                  <p>
                    To <code class="computeroutput"><span class="identifier">reference</span></code>
                  </p>
                </th>
<th>
                  <p>
                    To <code class="computeroutput"><span class="identifier">const_reference</span></code>
                  </p>
                </th>
<th>
                  <p>
                    To <code class="computeroutput"><span class="identifier">param_type</span></code>
                  </p>
                </th>
</tr></thead>
<tbody>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="identifier">T</span></code>
                  </p>
                </td>
<td>
                  <p>
                    iff <code class="computeroutput"><span class="identifier">T</span></code> is copy
                    constructible
                  </p>
                </td>
<td>
                  <p>
                    iff <code class="computeroutput"><span class="identifier">T</span></code> is copy
                    constructible
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="identifier">value_type</span></code>
                  </p>
                </td>
<td>
                  <p>
                    iff <code class="computeroutput"><span class="identifier">T</span></code> is copy
                    constructible
                  </p>
                </td>
<td>
                  <p>
                    iff <code class="computeroutput"><span class="identifier">T</span></code> is copy
                    constructible
                  </p>
                </td>
<td>
                  <p>
                    No
                  </p>
                </td>
<td>
                  <p>
                    No
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="identifier">reference</span></code>
                  </p>
                </td>
<td>
                  <p>
                    iff <code class="computeroutput"><span class="identifier">T</span></code> is copy
                    constructible
                  </p>
                </td>
<td>
                  <p>
                    iff <code class="computeroutput"><span class="identifier">T</span></code> is copy
                    constructible
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="identifier">const_reference</span></code>
                  </p>
                </td>
<td>
                  <p>
                    iff <code class="computeroutput"><span class="identifier">T</span></code> is copy
                    constructible
                  </p>
                </td>
<td>
                  <p>
                    No
                  </p>
                </td>
<td>
                  <p>
                    No
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="identifier">param_type</span></code>
                  </p>
                </td>
<td>
                  <p>
                    iff <code class="computeroutput"><span class="identifier">T</span></code> is copy
                    constructible
                  </p>
                </td>
<td>
                  <p>
                    iff <code class="computeroutput"><span class="identifier">T</span></code> is copy
                    constructible
                  </p>
                </td>
<td>
                  <p>
                    No
                  </p>
                </td>
<td>
                  <p>
                    No
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>
          If <code class="computeroutput"><span class="identifier">T</span></code> is an assignable type
          the following assignments are possible:
        </p>
<div class="table">
<a name="utility.utilities.call_traits.copy_constructibility.which_call_traits_types_are_assi"></a><p class="title"><b>Table 1.4. Which <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>
          types are assignable from which other types</b></p>
<div class="table-contents"><table class="table" summary="Which call_traits
          types are assignable from which other types">
<colgroup>
<col>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                </th>
<th>
                  <p>
                    To <code class="computeroutput"><span class="identifier">T</span></code>
                  </p>
                </th>
<th>
                  <p>
                    To <code class="computeroutput"><span class="identifier">value_type</span></code>
                  </p>
                </th>
<th>
                  <p>
                    To <code class="computeroutput"><span class="identifier">reference</span></code>
                  </p>
                </th>
<th>
                  <p>
                    To <code class="computeroutput"><span class="identifier">const_reference</span></code>
                  </p>
                </th>
<th>
                  <p>
                    To <code class="computeroutput"><span class="identifier">param_type</span></code>
                  </p>
                </th>
</tr></thead>
<tbody>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="identifier">T</span></code>
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
<td>
                  <p>
                    -
                  </p>
                </td>
<td>
                  <p>
                    -
                  </p>
                </td>
<td>
                  <p>
                    -
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="identifier">value_type</span></code>
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
<td>
                  <p>
                    -
                  </p>
                </td>
<td>
                  <p>
                    -
                  </p>
                </td>
<td>
                  <p>
                    -
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="identifier">reference</span></code>
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
<td>
                  <p>
                    -
                  </p>
                </td>
<td>
                  <p>
                    -
                  </p>
                </td>
<td>
                  <p>
                    -
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="identifier">const_reference</span></code>
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
<td>
                  <p>
                    -
                  </p>
                </td>
<td>
                  <p>
                    -
                  </p>
                </td>
<td>
                  <p>
                    -
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="identifier">param_type</span></code>
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
<td>
                  <p>
                    Yes
                  </p>
                </td>
<td>
                  <p>
                    -
                  </p>
                </td>
<td>
                  <p>
                    -
                  </p>
                </td>
<td>
                  <p>
                    -
                  </p>
                </td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break">
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility.utilities.call_traits.examples"></a><a name="sec:examples"></a><a class="link" href="call_traits.html#utility.utilities.call_traits.examples" title="Examples">Examples</a>
</h4></div></div></div>
<p>
          The following table shows the effect that <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a> has on various types.
        </p>
<div class="table">
<a name="utility.utilities.call_traits.examples.examples_of_call_traits_types"></a><p class="title"><b>Table 1.5. Examples of <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>
          types</b></p>
<div class="table-contents"><table class="table" summary="Examples of call_traits
          types">
<colgroup>
<col>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                </th>
<th>
                  <p>
                    <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>::<code class="computeroutput"><span class="identifier">value_type</span></code>
                  </p>
                </th>
<th>
                  <p>
                    <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>::<code class="computeroutput"><span class="identifier">reference</span></code>
                  </p>
                </th>
<th>
                  <p>
                    <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>::<code class="computeroutput"><span class="identifier">const_reference</span></code>
                  </p>
                </th>
<th>
                  <p>
                    <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>::<code class="computeroutput"><span class="identifier">param_type</span></code>
                  </p>
                </th>
<th>
                  <p>
                    Applies to:
                  </p>
                </th>
</tr></thead>
<tbody>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="identifier">my_class</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">my_class</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">my_class</span><span class="special">&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">my_class</span><span class="special">&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="identifier">my_class</span> <span class="keyword">const</span><span class="special">&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    All user-defined types
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="keyword">int</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">int</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">int</span><span class="special">&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">int</span> <span class="keyword">const</span></code>
                  </p>
                </td>
<td>
                  <p>
                    All small built-in types
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="keyword">int</span><span class="special">*</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">int</span><span class="special">*</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">int</span><span class="special">*&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">int</span><span class="special">*</span>
                    <span class="keyword">const</span> <span class="special">&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">int</span><span class="special">*</span>
                    <span class="keyword">const</span></code>
                  </p>
                </td>
<td>
                  <p>
                    All pointer types
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="keyword">int</span><span class="special">&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">int</span><span class="special">&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">int</span><span class="special">&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">int</span><span class="special">&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    All reference types
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span></code>
                  </p>
                </td>
<td>
                  <p>
                    All constant reference types
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="keyword">int</span><span class="special">[</span><span class="number">3</span><span class="special">]</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">*</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">int</span><span class="special">(&amp;)[</span><span class="number">3</span><span class="special">]</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">(&amp;)[</span><span class="number">3</span><span class="special">]</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">*</span> <span class="keyword">const</span></code>
                  </p>
                </td>
<td>
                  <p>
                    All array types
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    From <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">[</span><span class="number">3</span><span class="special">]</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">*</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">(&amp;)[</span><span class="number">3</span><span class="special">]</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">(&amp;)[</span><span class="number">3</span><span class="special">]</span></code>
                  </p>
                </td>
<td>
                  <p>
                    <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">*</span> <span class="keyword">const</span></code>
                  </p>
                </td>
<td>
                  <p>
                    All constant array types
                  </p>
                </td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p>
          The table assumes the compiler supports partial specialization: if it does
          not then all types behave in the same way as the entry for "<code class="computeroutput"><span class="identifier">my_class</span></code>", and <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a> can not be used with
          reference or array types.
        </p>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="utility.utilities.call_traits.examples.example_1"></a><a class="link" href="call_traits.html#utility.utilities.call_traits.examples.example_1" title="Example 1:">Example
          1:</a>
</h5></div></div></div>
<p>
            The following class is a trivial class that stores some type <code class="computeroutput"><span class="identifier">T</span></code> by value (see the <a href="../../../../../test/call_traits_test.cpp" target="_top"><code class="computeroutput"><span class="identifier">call_traits_test</span><span class="special">.</span><span class="identifier">cpp</span></code></a> file). The aim is to illustrate
            how each of the available <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a> <code class="computeroutput"><span class="keyword">typedef</span></code>s
            may be used:
          </p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">contained</span>
<span class="special">{</span>
   <span class="comment">// define our typedefs first, arrays are stored by value</span>
   <span class="comment">// so value_type is not the same as result_type:</span>
   <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">param_type</span>       <span class="identifier">param_type</span><span class="special">;</span>
   <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">reference</span>        <span class="identifier">reference</span><span class="special">;</span>
   <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">const_reference</span>  <span class="identifier">const_reference</span><span class="special">;</span>
   <span class="keyword">typedef</span> <span class="identifier">T</span>                                                <span class="identifier">value_type</span><span class="special">;</span>
   <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value_type</span>       <span class="identifier">result_type</span><span class="special">;</span>

   <span class="comment">// stored value:</span>
   <span class="identifier">value_type</span> <span class="identifier">v_</span><span class="special">;</span>

   <span class="comment">// constructors:</span>
   <span class="identifier">contained</span><span class="special">()</span> <span class="special">{}</span>
   <span class="identifier">contained</span><span class="special">(</span><span class="identifier">param_type</span> <span class="identifier">p</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">v_</span><span class="special">(</span><span class="identifier">p</span><span class="special">){}</span>
   <span class="comment">// return byval:</span>
   <span class="identifier">result_type</span> <span class="identifier">value</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">v_</span><span class="special">;</span> <span class="special">}</span>
   <span class="comment">// return by_ref:</span>
   <span class="identifier">reference</span> <span class="identifier">get</span><span class="special">()</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">v_</span><span class="special">;</span> <span class="special">}</span>
   <span class="identifier">const_reference</span> <span class="identifier">const_get</span><span class="special">()</span><span class="keyword">const</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">v_</span><span class="special">;</span> <span class="special">}</span>
   <span class="comment">// pass value:</span>
   <span class="keyword">void</span> <span class="identifier">call</span><span class="special">(</span><span class="identifier">param_type</span> <span class="identifier">p</span><span class="special">){}</span>

<span class="special">};</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="utility.utilities.call_traits.examples.example_2_the_reference_to_refer"></a><a name="sec:refs"></a><a class="link" href="call_traits.html#utility.utilities.call_traits.examples.example_2_the_reference_to_refer" title="Example 2 (the reference to reference problem):">Example
          2 (the reference to reference problem):</a>
</h5></div></div></div>
<p>
            Consider the definition of <a href="https://en.cppreference.com/w/cpp/utility/functional/binder12" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">binder1st</span></code></a>:
          </p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Operation</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">binder1st</span> <span class="special">:</span>
   <span class="keyword">public</span> <a href="https://en.cppreference.com/w/cpp/utility/functional/unary_function" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">unary_function</span></code></a><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Operation</span><span class="special">::</span><span class="identifier">second_argument_type</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Operation</span><span class="special">::</span><span class="identifier">result_type</span><span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">protected</span><span class="special">:</span>
   <span class="identifier">Operation</span> <span class="identifier">op</span><span class="special">;</span>
   <span class="keyword">typename</span> <span class="identifier">Operation</span><span class="special">::</span><span class="identifier">first_argument_type</span> <span class="identifier">value</span><span class="special">;</span>
<span class="keyword">public</span><span class="special">:</span>
   <span class="identifier">binder1st</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">Operation</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <span class="keyword">typename</span> <span class="identifier">Operation</span><span class="special">::</span><span class="identifier">first_argument_type</span><span class="special">&amp;</span> <span class="identifier">y</span><span class="special">);</span>
   <span class="keyword">typename</span> <span class="identifier">Operation</span><span class="special">::</span><span class="identifier">result_type</span> <span class="keyword">operator</span><span class="special">()(</span><span class="keyword">const</span> <span class="keyword">typename</span> <span class="identifier">Operation</span><span class="special">::</span><span class="identifier">second_argument_type</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="special">};</span>
</pre>
<p>
            Now consider what happens in the relatively common case that the functor
            takes its second argument as a reference, that implies that <code class="computeroutput"><span class="identifier">Operation</span><span class="special">::</span><span class="identifier">second_argument_type</span></code> is a reference
            type, <code class="computeroutput"><span class="keyword">operator</span><span class="special">()</span></code>
            will now end up taking a reference to a reference as an argument, and
            that is not currently legal. The solution here is to modify <code class="computeroutput"><span class="keyword">operator</span><span class="special">()</span></code>
            to use <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>:
          </p>
<pre class="programlisting"><span class="keyword">typename</span> <span class="identifier">Operation</span><span class="special">::</span><span class="identifier">result_type</span> <span class="keyword">operator</span><span class="special">()(</span><span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Operation</span><span class="special">::</span><span class="identifier">second_argument_type</span><span class="special">&gt;::</span><span class="identifier">param_type</span> <span class="identifier">x</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
            Now in the case that <code class="computeroutput"><span class="identifier">Operation</span><span class="special">::</span><span class="identifier">second_argument_type</span></code>
            is a reference type, the argument is passed as a reference, and the no
            "reference to reference" occurs.
          </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="utility.utilities.call_traits.examples.example_3_the_make_pair_problem"></a><a name="sec:example3"></a><a class="link" href="call_traits.html#utility.utilities.call_traits.examples.example_3_the_make_pair_problem" title="Example 3 (the make_pair problem):">Example
          3 (the <code class="computeroutput"><span class="identifier">make_pair</span></code> problem):</a>
</h5></div></div></div>
<p>
            If we pass the name of an array as one (or both) arguments to <code class="computeroutput"><a href="https://en.cppreference.com/w/cpp/utility/pair/make_pair" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">make_pair</span></code></a></code>, then template
            argument deduction deduces the passed parameter as "const reference
            to array of <code class="computeroutput"><span class="identifier">T</span></code>",
            this also applies to string literals (which are really array literals).
            Consequently instead of returning a pair of pointers, it tries to return
            a pair of arrays, and since an array type is not copy-constructible the
            code fails to compile. One solution is to explicitly cast the arguments
            to <a href="https://en.cppreference.com/w/cpp/utility/pair/make_pair" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">make_pair</span></code></a> to pointers, but
            <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>
            provides a better automatic solution that works safely even in generic
            code where the cast might do the wrong thing:
          </p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T2</span><span class="special">&gt;</span>
<a href="https://en.cppreference.com/w/cpp/utility/pair" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span></code></a><span class="special">&lt;</span>
   <span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">&gt;::</span><span class="identifier">value_type</span><span class="special">,</span>
   <span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">T2</span><span class="special">&gt;::</span><span class="identifier">value_type</span><span class="special">&gt;</span>
      <span class="identifier">make_pair</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T1</span><span class="special">&amp;</span> <span class="identifier">t1</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T2</span><span class="special">&amp;</span> <span class="identifier">t2</span><span class="special">)</span>
<span class="special">{</span>
   <span class="keyword">return</span> <a href="https://en.cppreference.com/w/cpp/utility/pair" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span></code></a><span class="special">&lt;</span>
      <span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">&gt;::</span><span class="identifier">value_type</span><span class="special">,</span>
      <span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">T2</span><span class="special">&gt;::</span><span class="identifier">value_type</span><span class="special">&gt;(</span><span class="identifier">t1</span><span class="special">,</span> <span class="identifier">t2</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
            Here, the deduced argument types will be automatically degraded to pointers
            if the deduced types are arrays, similar situations occur in the standard
            binders and adapters: in principle in any function that "wraps"
            a temporary whose type is deduced. Note that the function arguments to
            <a href="https://en.cppreference.com/w/cpp/utility/pair/make_pair" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">make_pair</span></code></a> are not expressed
            in terms of <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>:
            doing so would prevent template argument deduction from functioning.
          </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="utility.utilities.call_traits.examples.example_4_optimising_fill"></a><a name="sec:example4"></a><a class="link" href="call_traits.html#utility.utilities.call_traits.examples.example_4_optimising_fill" title="Example 4 (optimising fill):">Example
          4 (optimising fill):</a>
</h5></div></div></div>
<p>
            The <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>
            template will "optimize" the passing of a small built-in type
            as a function parameter. This mainly has an effect when the parameter
            is used within a loop body.
          </p>
<p>
            In the following example (see <a href="../../../../../../libs/type_traits/examples/fill_example.cpp" target="_top"><code class="computeroutput"><span class="identifier">fill_example</span><span class="special">.</span><span class="identifier">cpp</span></code></a>), a version of <a href="https://en.cppreference.com/w/cpp/algorithm/fill" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">fill</span></code></a> is optimized in two ways:
            if the type passed is a single byte built-in type then <a href="https://en.cppreference.com/w/cpp/string/byte/memset" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">memset</span></code></a> is used to effect the
            fill, otherwise a conventional C++ implementation is used, but with the
            passed parameter "optimized" using <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>:
          </p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">bool</span> <span class="identifier">opt</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">filler</span>
<span class="special">{</span>
   <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">I</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
   <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">do_fill</span><span class="special">(</span><span class="identifier">I</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">I</span> <span class="identifier">last</span><span class="special">,</span> <span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">param_type</span> <span class="identifier">val</span><span class="special">)</span>
   <span class="special">{</span>
      <span class="keyword">while</span><span class="special">(</span><span class="identifier">first</span> <span class="special">!=</span> <span class="identifier">last</span><span class="special">)</span>
      <span class="special">{</span>
         <span class="special">*</span><span class="identifier">first</span> <span class="special">=</span> <span class="identifier">val</span><span class="special">;</span>
         <span class="special">++</span><span class="identifier">first</span><span class="special">;</span>
      <span class="special">}</span>
   <span class="special">}</span>
<span class="special">};</span>

<span class="keyword">template</span> <span class="special">&lt;&gt;</span>
<span class="keyword">struct</span> <span class="identifier">filler</span><span class="special">&lt;</span><span class="keyword">true</span><span class="special">&gt;</span>
<span class="special">{</span>
   <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">I</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
   <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">do_fill</span><span class="special">(</span><span class="identifier">I</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">I</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">val</span><span class="special">)</span>
   <span class="special">{</span>
      <a href="https://en.cppreference.com/w/cpp/string/byte/memset" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">memset</span></code></a><span class="special">(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">val</span><span class="special">,</span> <span class="identifier">last</span><span class="special">-</span><span class="identifier">first</span><span class="special">);</span>
   <span class="special">}</span>
<span class="special">};</span>

<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">I</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">inline</span> <span class="keyword">void</span> <span class="identifier">fill</span><span class="special">(</span><span class="identifier">I</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">I</span> <span class="identifier">last</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">val</span><span class="special">)</span>
<span class="special">{</span>
   <span class="keyword">enum</span> <span class="special">{</span> <span class="identifier">can_opt</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_pointer</span><span class="special">&lt;</span><span class="identifier">I</span><span class="special">&gt;::</span><span class="identifier">value</span>
                   <span class="special">&amp;&amp;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_arithmetic</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value</span>
                   <span class="special">&amp;&amp;</span> <span class="special">(</span><span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">T</span><span class="special">)</span> <span class="special">==</span> <span class="number">1</span><span class="special">)</span> <span class="special">};</span>
   <span class="keyword">typedef</span> <span class="identifier">filler</span><span class="special">&lt;</span><span class="identifier">can_opt</span><span class="special">&gt;</span> <span class="identifier">filler_t</span><span class="special">;</span>
   <span class="identifier">filler_t</span><span class="special">::</span><span class="keyword">template</span> <span class="identifier">do_fill</span><span class="special">&lt;</span><span class="identifier">I</span><span class="special">,</span><span class="identifier">T</span><span class="special">&gt;(</span><span class="identifier">first</span><span class="special">,</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">val</span><span class="special">);</span>
<span class="special">}</span>
</pre>
<p>
            The reason that this is "optimal" for small built-in types
            is that with the value passed as <code class="computeroutput"><span class="identifier">T</span>
            <span class="keyword">const</span></code> instead of <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span></code> the compiler is able to tell both
            that the value is constant and that it is free of aliases. With this
            information the compiler is able to cache the passed value in a register,
            unroll the loop, or use explicitly parallel instructions: if any of these
            are supported. Exactly how much mileage you will get from this depends
            upon your compiler - we could really use some accurate benchmarking software
            as part of boost for cases like this.
          </p>
<p>
            Note that the function arguments to fill are not expressed in terms of
            <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>:
            doing so would prevent template argument deduction from functioning.
            Instead fill acts as a "thin wrapper" that is there to perform
            template argument deduction, the compiler will optimise away the call
            to fill all together, replacing it with the call to <code class="computeroutput"><span class="identifier">filler</span><span class="special">&lt;&gt;::</span><span class="identifier">do_fill</span></code>,
            which does use <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>.
          </p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility.utilities.call_traits.rationale"></a><a class="link" href="call_traits.html#utility.utilities.call_traits.rationale" title="Rationale">Rationale</a>
</h4></div></div></div>
<p>
          The following notes are intended to briefly describe the rationale behind
          choices made in <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>.
        </p>
<p>
          All user-defined types follow "existing practice" and need no
          comment.
        </p>
<p>
          Small built-in types, what the standard calls <a href="https://en.cppreference.com/w/cpp/language/types" target="_top">fundamental
          types</a>, differ from existing practice only in the <code class="computeroutput"><span class="identifier">param_type</span></code> <code class="computeroutput"><span class="keyword">typedef</span></code>.
          In this case passing <code class="computeroutput"><span class="identifier">T</span> <span class="keyword">const</span></code> is compatible with existing practice,
          but may improve performance in some cases (see <a class="link" href="call_traits.html#sec:example4">Example
          4</a>). In any case this should never be any worse than existing practice.
        </p>
<p>
          Pointers follow the same rationale as small built-in types.
        </p>
<p>
          For reference types the rationale follows <a class="link" href="call_traits.html#sec:refs">Example
          2</a> - references to references are not allowed, so the <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a> members must be defined
          such that these problems do not occur. There is a proposal to modify the
          language such that "a reference to a reference is a reference"
          (issue #106, submitted by Bjarne Stroustrup). <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code></a><code class="computeroutput"><span class="special">::</span><span class="identifier">value_type</span></code>
          and <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code></a><code class="computeroutput"><span class="special">::</span><span class="identifier">param_type</span></code> both provide the same effect
          as that proposal, without the need for a language change. In other words,
          it's a workaround.
        </p>
<p>
          For array types, a function that takes an array as an argument will degrade
          the array type to a pointer type: this means that the type of the actual
          parameter is different from its declared type, something that can cause
          endless problems in template code that relies on the declared type of a
          parameter.
        </p>
<p>
          For example:
        </p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">A</span>
<span class="special">{</span>
   <span class="keyword">void</span> <span class="identifier">foo</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">t</span><span class="special">);</span>
<span class="special">};</span>
</pre>
<p>
          In this case if we instantiate <code class="computeroutput"><span class="identifier">A</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">[</span><span class="number">2</span><span class="special">]&gt;</span></code>
          then the declared type of the parameter passed to member function <code class="computeroutput"><span class="identifier">foo</span></code> is <code class="computeroutput"><span class="keyword">int</span><span class="special">[</span><span class="number">2</span><span class="special">]</span></code>,
          but its actual type is <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span><span class="special">*</span></code>. If
          we try to use the type <code class="computeroutput"><span class="identifier">T</span></code>
          within the function body, then there is a strong likelihood that our code
          will not compile:
        </p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">A</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">foo</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">t</span><span class="special">)</span>
<span class="special">{</span>
   <span class="identifier">T</span> <span class="identifier">dup</span><span class="special">(</span><span class="identifier">t</span><span class="special">);</span> <span class="comment">// doesn't compile for case that T is an array.</span>
<span class="special">}</span>
</pre>
<p>
          By using <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>
          the degradation from array to pointer is explicit, and the type of the
          parameter is the same as it's declared type:
        </p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">A</span>
<span class="special">{</span>
   <span class="keyword">void</span> <span class="identifier">foo</span><span class="special">(</span><span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value_type</span> <span class="identifier">t</span><span class="special">);</span>
<span class="special">};</span>

<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">void</span> <span class="identifier">A</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">foo</span><span class="special">(</span><span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value_type</span> <span class="identifier">t</span><span class="special">)</span>
<span class="special">{</span>
   <span class="keyword">typename</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">value_type</span> <span class="identifier">dup</span><span class="special">(</span><span class="identifier">t</span><span class="special">);</span> <span class="comment">// OK even if T is an array type.</span>
<span class="special">}</span>
</pre>
<p>
          For <code class="computeroutput"><span class="identifier">value_type</span></code> (return
          by value), again only a pointer may be returned, not a copy of the whole
          array, and again <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>
          makes the degradation explicit. The <code class="computeroutput"><span class="identifier">value_type</span></code>
          member is useful whenever an array must be explicitly degraded to a pointer
          - <a class="link" href="call_traits.html#sec:example3">Example 3</a> provides the test case.
        </p>
<p>
          Footnote: the array specialisation for <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a> is the least well
          understood of all the <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits"><code class="computeroutput"><span class="identifier">call_traits</span></code></a>
          specialisations. If the given semantics cause specific problems for you,
          or does not solve a particular array-related problem, then I would be interested
          to hear about it. Most people though will probably never need to use this
          specialisation.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="call_traits.reference"></a>Reference</h4></div></div></div>
<div class="section">
<div class="titlepage"><div><div><h5 class="title">
<a name="header.boost.detail.call_traits_hpp"></a>Header &lt;<a href="../../../../../../boost/detail/call_traits.hpp" target="_top">boost/detail/call_traits.hpp</a>&gt;</h5></div></div></div>
<pre class="synopsis"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../../boost/call_traits.html" title="Struct template call_traits">call_traits</a><span class="special">;</span>

  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T<span class="special">&gt;</span> <span class="keyword">struct</span> <a class="link" href="../../boost/call_traits_T___idm2906.html" title="Struct template call_traits&lt;T &amp;&gt;">call_traits</a><span class="special">&lt;</span><span class="identifier">T</span> <span class="special">&amp;</span><span class="special">&gt;</span><span class="special">;</span>
<span class="special">}</span></pre>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001 Beman Dawes<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../../BOOST_BINARY_LITERAL_D.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../utilities.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../../boost/call_traits.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
